#include "..\\stdafx.h"
#include "UIXmlEx.h"
#include "FCDraw.h"
#include "MyChart.h"
#include "LatestDiv.h"
#include "SecurityList.h"

UIXmlEx::UIXmlEx(){
    m_scaleFactor = 1;
}

double UIXmlEx::getScaleFactor()
{
    return m_scaleFactor;
}

void UIXmlEx::setScaleFactor(double value){
    m_scaleFactor = value;
    if (getNative() != 0)
    {
        getNative()->getPaint()->setScaleFactor(m_scaleFactor, m_scaleFactor);
    }
}

FCView* UIXmlEx::createView(IXMLDOMNode *node, const String& type){
    int typeLen = type.length();
    switch (typeLen)
    {
        case 7:
            if (type == L"mychart")
            {
                return new MyChart();
            }
            break;
        case 9:
            {
                if (type == L"latestdiv")
                {
                    return new LatestDiv();
                }
                break;
            }
    }
    if (typeLen > 10)
    {
        if (type == L"securitylist")
        {
            return new SecurityList();
        }
    }
    return FCUIXml::createView(node, type);
}

void UIXmlEx::resetScaleSize(FCSize clientSize){
    FCNative *native = getNative();
    if (native != 0)
    {
        FCSize size;
        size.cx = (int)(clientSize.cx * m_scaleFactor);
        size.cy = (int)(clientSize.cy * m_scaleFactor);
        native->setScaleSize(size);
        native->update();
    }
}
